<?php


 class CommonUtils
 {
	//const img_path = $this->Application->Parameters['ImagePath'];
	
	
	public static function getAvatar($img_path,$user)
	{
		//echo "<br>avatar  " . $user->username;
		if($user->avatarPath == null)
		{
			
			if($user->sex == 0) // get Default Avatar , according to sex
				return $img_path . "/avatarF.png";
			else
				return $img_path . "/avatarM.png";
		}
		
		// avatarPath is NOT NULL
		$path = $img_path ."/". $user->user_id . "/" . $user->avatarPath;
		//$path = $this->Application->AssetManager->getBaseUrl() ."/images/".$user->user_id ."/" . $user->avatarPath;
//		echo "<br/>".$path ."<br/>";
		return $path;	
	}
	
	/**
	 * set Error message and style to Control
	 */
	public function setError($control,$msg)
	{
		$html = "<div class='error notification'>".$msg."</div>";
		$control->Text = $html;
	}
	
	/**
	 * set sucess message and style to Control
	 */
	public function setNotification($control,$msg)
	{
		$html = "<div class='success notification'>".$msg."</div>";
		$control->Text = $html;
	}
	
	public static function getExtension($filename)
	{
		$pos = strrpos($filename, '.');
		
		if($pos===false) {
			return false;
		} else {
			return substr($filename, $pos+1);
		}
			
	}
	
	public static function getUniqueFileName($filename)
	{		
		$pos = strrpos($filename, '.');
		
		if($pos===false) {
			return $filename;
		} else {
			$dotWithExt =  substr($filename, $pos);
			$unique = str_replace($dotWithExt,"",$filename);
			$unique = $unique . uniqid() . $dotWithExt;
			
			return $unique;
		}
	}

 }